<?php
/*
 * Copyright (C) 2009 Jeffrey Palm
 */

  /*
   * INPUT:
   * $ITEMS = array(...)
   *  - An array of links to print as a list.
   */

require_once BASE . 'util.php';

$its = $ITEMS;

// If we don't have any, read from the file system
$convertName = FALSE;
if (count($its) == 0) {
  $its = list_dirs();
  $convertName = TRUE;
 }

sort($its);

if (!isIPhone()) {
  echo '<div id="container-wrapper">';
 }
$i = 0;
$N = 30;
if (defined('NUM_MENU_ITEMS')) {
  $N = NUM_MENU_ITEMS;
 }
$needClose = FALSE;
foreach ($its as $item) {
  if (isIPhone()) {
    echo '<li class="page_item page-item-2">';
  } else {
    if ($i == 0) {
      echo ' <div class="container">';
      $needClose = TRUE;
    }
  }
  echo linkTo($item,$convertName);
  if (isIPhone()) {
    echo '</li>';
  } else {
    echo br();
  }
  echo "\n";
  if (++$i > $N) {
    echo '</div>';
    $i = 0;
  }
}
if (!isIPhone()) {

  // Maybe close the container div
  if ($needClose) {
    echo '</div>';
  }

  // Close the container-wrapper div
  echo '</div>';
 }

?>